#coding=utf-8
import urllib
import re
import time

global x
x = 1

def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html

def getImg(html):
    global x
    reg = r'src="(.+?\.jpg)" alt='
    imgre = re.compile(reg)
    imglist = re.findall(imgre,html)
    for imgurl in imglist:
        urllib.urlretrieve(imgurl,'%s.jpg' % x)
        x += 1
    return imglist

def delayRun():
    i = 1
    while i <= 65:
        time.sleep(2)
        url = "http://www.mzitu.com/80661/" + str(i)
        html = getHtml(url)
        getImg(html)
        i += 1


if __name__ == '__main__':
    global x
    delayRun()